<?php

namespace App\Models;

class AdminAgencys extends Base
{
    protected $table = 'admin_agencys';

    const IS_READ_1 = 1;
    const IS_READ_2 = 2;
    const IS_READ_TEXT = [
        self::IS_READ_1 => '<span class="el-tag el-tag--danger">未读</span>',
        self::IS_READ_2 => '<span class="el-tag">已读</span>',
    ];

    const TYPE_1 = 1;
    const TYPE_2 = 2;
    const TYPE_3 = 3;
    const TYPE_4 = 4;
    const TYPE_5 = 5;
    const TYPE_TEXT = [
        self::TYPE_1 => '<span class="el-tag el-tag--primary">店铺</span>',
        self::TYPE_2 => '<span class="el-tag el-tag--success">活动</span>',
        self::TYPE_3 => '<span class="el-tag el-tag--info">商品</span>',
        self::TYPE_4 => '<span class="el-tag el-tag--warning">需求</span>',
        self::TYPE_5 => '<span class="el-tag el-tag--danger">快速发布</span>',
    ];

    protected $fillable = [
        'id','title','type','is_read','status','created_at','updated_at'
    ];

    /**
     * 获取列表
     * @param array $params 条件参数
     * @param array $fields 查询的字段
     * @param int $limit 分页数量
     * @return mixed
     */
    protected function getList($params = [], $fields = ['*']){
        $lists = $this->select($fields)
            ->where(function ($query) use ($params) {
                if(isset($params['type']) && $params['type']) {
                    $query ->where('type',$params['type']);
                }
                if(isset($params['is_read']) && $params['is_read']) {
                    $query ->where('is_read',$params['is_read']);
                }
            })->where('status','<>',-1)->get();
        $this->stateToText($lists,[
            'type'      => self::TYPE_TEXT,
            'is_read'   => self::IS_READ_TEXT,
        ]);
        return $lists;
    }

}
